import { getSidebar, setSidebar } from '../../utils/auth'

const app = {
  state: {
    sidebar: getSidebar() === 'true',
    isMobile: 'mobile',
    isCloseSidebar: true
  },
  mutations: {
    SET_SIDEBAR: (state, value) => {
      state.sidebar = value
    },
    SET_IS_MOBILE: (state, value) => {
      state.isMobile = value
    },
    SET_CLOSE_SIDEBAR: (state, value) => {
      state.isCloseSidebar = value
    }
  },
  actions: {
    // 设置菜单展开或收起
    setSidebar ({ commit }, value) {
      setSidebar(value)
      commit('SET_SIDEBAR', value)
    },

    // 设置是否移动端还是pc
    setIsMobile ({ commit }, value) {
      commit('SET_IS_MOBILE', value)
    },

    // 导航栏是否全部隐藏
    setIsCloseSidebar ({ commit }, value) {
      commit('SET_CLOSE_SIDEBAR', value)
    }
  }
}

export default app
